import * as types from './../constants/ActionTypes';

/*
 * 找回密码 step 1
 ================================================================*/
export function findpwd(phone){
    return (dispatch) => {
        
        let payload = { 
            findpwd_status : 0, 
            message : '', 
            phone : phone
        };

        dispatch({
            payload, 
            type : [types.FINDPWD, types.FINDPWD_SUCCESS, types.FINDPWD_FAILURE],
            meta: {
                fetch: [`members/chkphone?phone=${phone}`, {
                        method: 'get'
                    }
                ]
            }  
        });
    };
}

/*
 * 找回密码 step 2
 ================================================================*/
export function findpwd2({phone, captcha, password} = {}){
    return (dispatch) => {
        
        let payload = { 
            findpwd2_status : 0, 
            message : '',
            phone : phone,
            captcha: captcha,
            password : password
        };

        dispatch({
            payload, 
            type : [types.FINDPWD2, types.FINDPWD2_SUCCESS, types.FINDPWD2_FAILURE],
            meta: {
                fetch: [`members/restpwd`, {
                        method: 'post',
                        body: `phone=${phone}&captcha=${captcha}&password=${password}`
                    }
                ]
            }  
        });
    };
}